package com.bl.student.manager.controller.task;

import com.bl.student.manager.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.service.biz.task.TaskService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.comment.CommentAddVo;
import com.bl.student.service.vo.confirm.ConfirmAddVo;
import com.bl.student.service.vo.task.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by liangweikang on 18/1/29.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/task"})
@Api(value = "发布任务 ", description = "发布任务相关api")
public class TaskController extends BaseController {
    @Autowired
    TaskService taskService;

    @ApiOperation(value = "多条件筛选", notes = "多条件筛选 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/get_task_list_multi"})
    public ApiResponseBody modify(
            @Valid @RequestBody TaskSearchVo body, BindingResult result,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(body.getPage() - 1, body.getSize());

        TaskListVo taskListVo = taskService.getTaskListsMulti(body.getClassc(),body.getClassb(),body.getClassa(),body.getOnline(),body.getSex(),body.getPrice(),body.getLanguage(),body.getGrade(),body.getCollege(),body.getType(),
                body.getStar(),body.getLocation(),body.getTime(),body.getCount(),body.getRole(),body.getChinese(),body.getEnv(),body.getTSex(),pageable,body.getStatus(),0,0, body.getBuyType(), body.getRunType(), "time");

        return ApiResponseBody.createSuccessBody(taskListVo);
    }

    @ApiOperation(value = "删除任务", notes = "删除任务 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        taskService.del(body, getUserInfo(request).getId());

        return ApiResponseBody.createSuccessBody(null);
    }


}
